/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.entity.OmICheckSheetDetail;
import com.excesys.exsecs.om.service.OmICheckSheetDetailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * weiyj
 *
 * @author pig code generator
 * @date 2023-03-20 14:04:16
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/omichecksheetdetail")
@Tag(name = "巡检记录管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmICheckSheetDetailController {

	private final OmICheckSheetDetailService omICheckSheetDetailService;

	/**
	 * 分页查询
	 *
	 * @param page                分页对象
	 * @param omICheckSheetDetail 巡检记录
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_get')")
	public R getOmICheckSheetDetailPage(Page page, OmICheckSheetDetail omICheckSheetDetail) {
		return R.ok(omICheckSheetDetailService.page(page, Wrappers.query(omICheckSheetDetail)));
	}

	/**
	 * 列表查询
	 *
	 * @param omICheckSheetDetail 巡检点位表
	 * @return
	 */
	@Operation(summary = "列表查询", description = "列表查询")
	@GetMapping("/list")
	// @PreAuthorize("@pms.hasPermission('om_omicheckpoint_get')" )
	public R<List<OmICheckSheetDetail>> getOmICheckSheetDetailList(OmICheckSheetDetail omICheckSheetDetail) {
		return R.ok(omICheckSheetDetailService.list(Wrappers.query(omICheckSheetDetail)));
	}

	/**
	 * 通过id查询巡检记录
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_get')")
	public R getById(@PathVariable("id") Integer id) {
		return R.ok(omICheckSheetDetailService.getById(id));
	}

	/**
	 * 通过id查询巡检记录
	 *
	 * @param omICheckSheetDetail
	 * @return R
	 */
	@Operation(summary = "通过条件查询", description = "通过条件查询")
	@GetMapping("/getByDetail")
	// @PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_get')" )
	public R getByDetail(OmICheckSheetDetail omICheckSheetDetail) {
		return R.ok(omICheckSheetDetailService.getOne(Wrappers.query(omICheckSheetDetail)));
	}

	/**
	 * 新增巡检记录
	 *
	 * @param omICheckSheetDetail 巡检记录
	 * @return R
	 */
	@Operation(summary = "新增巡检记录", description = "新增巡检记录")
	@SysLog("新增巡检记录")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_add')")
	public R save(@RequestBody OmICheckSheetDetail omICheckSheetDetail) {
		return R.ok(omICheckSheetDetailService.save(omICheckSheetDetail));
	}

	/**
	 * 新增巡检记录
	 *
	 * @param detailList 巡检记录
	 * @return R
	 */
	@Operation(summary = "新增巡检记录多个", description = "新增巡检记录多个")
	@SysLog("新增巡检记录多个")
	@PostMapping("/saveDetail")
	// @PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_add')" )
	public R saveDeatil(@RequestBody List<OmICheckSheetDetail> detailList) {
		return R.ok(omICheckSheetDetailService.saveDetail(detailList));
	}

	/**
	 * 修改巡检记录
	 *
	 * @param omICheckSheetDetail 巡检记录
	 * @return R
	 */
	@Operation(summary = "修改巡检记录", description = "修改巡检记录")
	@SysLog("修改巡检记录")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_edit')")
	public R updateById(@RequestBody OmICheckSheetDetail omICheckSheetDetail) {
		return R.ok(omICheckSheetDetailService.updateById(omICheckSheetDetail));
	}

	/**
	 * 通过id删除巡检记录
	 *
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除巡检记录", description = "通过id删除巡检记录")
	@SysLog("通过id删除巡检记录")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('om_omichecksheetdetail_del')")
	public R removeById(@PathVariable Integer id) {
		return R.ok(omICheckSheetDetailService.removeById(id));
	}

}
